package com.hxd.otc.dialog;

import android.content.Context;
import android.view.View;

import com.flyco.dialog.widget.base.BottomBaseDialog;
import com.hxd.otc.R;
import com.hxd.otc.common.UserHelper;
import com.hxd.otc.common.enums.ExValidType;
import com.hxd.otc.widget.BlocksToast;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class SelectExValidTypeDialog extends BottomBaseDialog<SelectExValidTypeDialog> {
    public SelectExValidTypeDialog(Context context) {
        super(context);
    }

    @Override
    public View onCreateView() {
        return View.inflate(getContext(), R.layout.dialog_select_ex_valid_type, null);
    }

    @Override
    public void onViewCreated(View view) {
        ButterKnife.bind(this, view);
    }

    @Override
    public void setUiBeforShow() {
    }

    @OnClick({R.id.tv_google_auth, R.id.tv_sms_auth,R.id.tv_email_auth, R.id.tv_cancel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_google_auth:
                onGoogleAuth();
                break;
            case R.id.tv_sms_auth:
                onSmsAuth();
                break;
            case R.id.tv_email_auth:
                onEmailAuth();
                break;
            case R.id.tv_cancel:
                dismiss();
                break;
        }
    }

    private void onGoogleAuth() {
        if (!UserHelper.isSetGoogleAuth()) {
            BlocksToast.get().showToast(R.string.you_not_set_google_auth);
            return;
        }

        if (ExValidType.GoogleAuth.equals(UserHelper.getExValidType())){
            BlocksToast.get().showToast(R.string.your_verification_mode_alredy_is_goole_code);
            return;
        }

        if (onSelectExValidTypeListener != null) {
            onSelectExValidTypeListener.onSetExValidType(ExValidType.GoogleAuth);
        }
        dismiss();
    }

    private void onEmailAuth() {
        if (!UserHelper.isBoundEmail()){
            BlocksToast.get().showToast(R.string.your_are_not_bound_email);
            return;
        }

        if (ExValidType.Email.equals(UserHelper.getExValidType())){
            BlocksToast.get().showToast(R.string.your_verification_mode_alredy_is_email_auth);
            return;
        }

        if (onSelectExValidTypeListener != null) {
            onSelectExValidTypeListener.onSetExValidType(ExValidType.Email);
        }
        dismiss();
    }

    private void onSmsAuth() {
        if (!UserHelper.isBoundPhone()){
            BlocksToast.get().showToast(R.string.your_are_not_bound_phone);
            return;
        }

        if (ExValidType.SMS.equals(UserHelper.getExValidType())){
            BlocksToast.get().showToast(R.string.your_verification_mode_alredy_is_sms_auth);
            return;
        }

        if (onSelectExValidTypeListener != null) {
            onSelectExValidTypeListener.onSetExValidType(ExValidType.SMS);
        }
        dismiss();
    }


    private OnSelectExValidTypeListener onSelectExValidTypeListener;

    public SelectExValidTypeDialog setOnSelectExValidTypeListener(OnSelectExValidTypeListener onSelectExValidTypeListener) {
        this.onSelectExValidTypeListener = onSelectExValidTypeListener;
        return this;
    }

    public interface OnSelectExValidTypeListener {
        void onSetExValidType(ExValidType newExValidType);

    }
}
